package com.more.spring.boot;

import com.more.spring.boot.config.SqlSessionFactoryConfig;
import com.more.spring.boot.mapper.UserMapper;
import com.more.spring.boot.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.io.IOException;
import java.util.List;

public class SqlSessoinTest4 {

    public static void main(String[] args) throws IOException {
        //构建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryConfig.getSqlSessionFactory();

        try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);


           int i=  mapper.insertUser(new User(4445, "44445","女"));
            System.out.println("插入结果：" + i);

            if (i > 0) {
                //提交数据
                sqlSession.commit();
            }

//            List<User> users = mapper.selectAllUser();

            List<User> users = mapper.selectUserList();
            for (User user : users) {
                System.out.println(user);
            }
        }
    }
}
